'use strict';

const { Service } = require('ee-core');
const db = require('../utils/mssql')

/**
 * 示例服务（service层为单例）
 * @class
 */
class ExampleService extends Service {

  constructor(ctx) {
    super(ctx);
  }

  /**
   * test
   */
  async test(args) {
    let obj = {
      status:'ok',
      params: args
    }

    return obj;
  }

  async getZdList() {
    const date = new Date()
    const today = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
    return new Promise((resolve) => {
      db.select('Sale', '100', `where Dte >= '${today}'`, '', 'order by Dte desc', (err, result) => {
        resolve(result)
      })
    })
  }

  async getSingleMx(billID) {
    return new Promise((resolve) => {
      db.select('SaleLine', 500, `where billID = '${billID}'`, '', '', (err, result) => {
        resolve(result)
      })
    })
  }
}

ExampleService.toString = () => '[class ExampleService]';
module.exports = ExampleService;